﻿/*
 * Ejemplo de Statemanager XNA 4.0
 * 
 * 100% XNA & XNACommunity- 2010
 * http://100xna.wordpress.com/
 * http://xnacommunity.codeplex.com
 * 
 */

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace StateExample
{
    public class MenuState : State
    {
        protected SpriteBatch spriteBatch;
        protected SpriteFont fuente;


        protected KeyboardState tecladoAnterior;
        protected KeyboardState tecladoActual;

        protected Menu menu = new Menu();


        public MenuState(Game game) : base(game)
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            fuente = Content.Load<SpriteFont>("menu");

            tecladoActual = tecladoAnterior = Keyboard.GetState();
        }

        /// <summary>
        /// Actualiza el menu
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime)
        {
            tecladoActual = Keyboard.GetState();

            if (tecladoActual.IsKeyDown(Keys.Enter) && !tecladoAnterior.IsKeyDown(Keys.Enter))
            {
                if (menu.SelectedItem != null)
                    menu.SelectedItem.PerformActivate();
            }

            if (tecladoActual.IsKeyDown(Keys.Up) && !tecladoAnterior.IsKeyDown(Keys.U))
            {
                menu.SelectPrevious();
            }

            if (tecladoActual.IsKeyDown(Keys.Down) && !tecladoAnterior.IsKeyDown(Keys.Down))
            {
                menu.SelectNext();
            }

            tecladoAnterior = tecladoActual;
        }

        public override void Draw(GameTime gameTime)
        {
            menu.Draw(spriteBatch, fuente);
        }
    }
}
